package com.vcredit.creditcat.web.api;

import com.alibaba.dubbo.config.annotation.Reference;
import com.vcredit.creditcat.api.ISMSMessageManager;
import com.vcredit.creditcat.enumtype.SendSmsTypeEnum;
import com.vcredit.framework.annotation.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by wichell on 2017/7/18.
 */
@RestController
@RequestMapping("/vercode")
public class VerCodeController extends BaseCreditCatController{
	private Logger logger = LoggerFactory.getLogger(VerCodeController.class);

	@Reference(version = "1.0")
	private ISMSMessageManager SMSmessageManager;

	/**
	 * 发送短信验证码
	 * @author wichell
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@Log
	@RequestMapping(value = "/send")
	public Integer sendSMS(HttpServletRequest request) {
		try {
			String mobile = request.getParameter("mobile");
			String code = request.getParameter("vercode");
			Integer businessType = SendSmsTypeEnum.BBSVerCode.getCode();
			SMSmessageManager.sendVerificationCode(mobile, code, businessType);
			return 1;
		} catch (Exception ex) {
			logger.error(ex.toString());
		}
		return 0;
	}
}
